package com.alks.function.controller.biocontrol.webWork;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.entity.data.entity.PcCuttingLsHead;
import com.alks.entity.data.entity.PsScheduleHead;
import com.alks.entity.data.entity.PsScheduleLot;
import com.alks.entity.data.page.PageRecord;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.dto.biocontrol.webwork.MoldProgTempDto;
import com.alks.function.data.dto.biocontrol.webwork.SchLineDto;
import com.alks.function.data.request.biocontrol.deptwork.SchHeadMovRequest;
import com.alks.function.data.request.biocontrol.webwork.CancelSchRequest;
import com.alks.function.data.request.biocontrol.webwork.MoldProgtTempRequest;
import com.alks.function.mapper.biocontrol.webwork.PsScheduleLotMapper;
import com.alks.function.service.biocontrol.deptwork.IMoldProgService;
import com.alks.function.service.biocontrol.deptwork.IPsScehduleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author MS
 * @since 2024/10/5下午4:44
 */

@RestController
@ApiRestController("/Mold/Prog")
@Api(value = "生控部", tags = "生控部-web查询-成型进度")
@Slf4j
public class MoldProgController {
    @Autowired
    private IMoldProgService service;
    @Autowired
    private IPsScehduleService schService;

    @WebLogger
    @PostMapping("/temp")
    @ApiOperation(value = "待安排指令", tags = "生控部-web查询-成型进度")
    public ResponseInfo temp(@RequestBody MoldProgtTempRequest request) {
        PageRecord<MoldProgTempDto> dtoList = service.temp(request);
        return ResponseInfo.ok(dtoList);
    }

    @WebLogger
    @PostMapping("/line/temp")
    @ApiOperation(value = "生产线", tags = "生控部-web查询-成型进度")
    public ResponseInfo lineTemp() {
        List<SchLineDto> dtoList = service.lineTemp();
        return ResponseInfo.ok(dtoList);
    }

    @WebLogger
    @PostMapping("/detail")
    @ApiOperation(value = "已排进度明细", tags = "生控部-web查询-成型进度")
    public ResponseInfo detail(@RequestBody MoldProgtTempRequest request) {
        PageRecord<PsScheduleHead> dto = service.detail(request);
        return ResponseInfo.ok(dto);
    }

    @WebLogger
    @GetMapping("/update/lot")
    @ApiOperation(value = "指令更新", tags = "生控部-web查询-成型进度")
    public ResponseInfo upLot() {
        service.upLot();
        return ResponseInfo.ok();
    }

    @WebLogger
    @PostMapping("/sch/ls")
    @ApiOperation(value = "拆单安排", tags = "生控部-web查询-成型进度")
    public ResponseInfo lsSch(@RequestBody@ApiParam("批次") List<Integer> lsNo,
                              @RequestParam@ApiParam("指令")  String lotNo,
                              @RequestParam String line,
                              @RequestParam BigDecimal seqNo) {
        service.lsSch(lotNo,lsNo,line,seqNo);
        return ResponseInfo.ok();
    }

    @WebLogger
    @PostMapping("/ls/query")
    @ApiOperation(value = "拆单安排查询", tags = "生控部-web查询-成型进度")
    public ResponseInfo lsQuery(@RequestParam@ApiParam("指令")  String lotNo) {
        List<PcCuttingLsHead> heads = service.lsQuery(lotNo);
        return ResponseInfo.ok(heads);
    }

    @WebLogger
    @PutMapping("/sch")
    @ApiOperation(value = "整单安排", tags = "生控部-web查询-成型进度")
    public ResponseInfo allSch(@RequestBody List<String> lotNoList,
                               @RequestParam String line,
                               @RequestParam BigDecimal seqNo) {
        service.allSch(lotNoList,line,seqNo);
        return ResponseInfo.ok();
    }

    @WebLogger
    @PutMapping("/ud")
    @ApiOperation(value = "上移下移", tags = "生控部-web查询-成型进度")
    public ResponseInfo headUd(@RequestBody SchHeadMovRequest request) {
        schService.indexUpDown(request);
        return ResponseInfo.ok();
    }

    @WebLogger
    @PutMapping("/list/ud")
    @ApiOperation(value = "批量上下移", tags = "生控部-web查询-成型进度")
    public ResponseInfo headListUd(@RequestBody SchHeadMovRequest request) {
        schService.indexMove(request);
        return ResponseInfo.ok();
    }

    @WebLogger
    @PutMapping("/line/move")
    @ApiOperation(value = "批量移线", tags = "生控部-web查询-成型进度")
    public ResponseInfo lineMove(@RequestBody SchHeadMovRequest request) {
        schService.lineMove(request);
        return ResponseInfo.ok();
    }

    @WebLogger
    @PutMapping("/sch/cancel")
    @ApiOperation(value = "取消安排", tags = "生控部-web查询-成型进度")
    public ResponseInfo cancelSch(@RequestBody List<CancelSchRequest> request) {
        service.cancelSch(request);
        return ResponseInfo.ok();
    }

    @WebLogger
    @GetMapping("/sch/order")
    @ApiOperation(value = "序号重排", tags = "生控部-web查询-成型进度")
    public ResponseInfo reOrder() {
        service.reOrder();
        return ResponseInfo.ok();
    }

    @WebLogger
    @GetMapping("/brand/back")
    @ApiOperation(value = "品牌回显", tags = "生控部-web查询-成型进度")
    public ResponseInfo brandBack(@RequestParam(required = false)@ApiParam("模糊匹配客户") String brand) {
        List<String> brandList =service.brandBack(brand);
        return ResponseInfo.ok(brandList);
    }

    @WebLogger
    @GetMapping("/sch/up")
    @ApiOperation(value = "更新进度表", tags = "生控部-web查询-成型进度")
    public ResponseInfo schUp() {
        service.schUp();
        return ResponseInfo.ok();
    }

}